<?php

class Home extends Admin_Controller {
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function index()
	{
		$this->template->display('home/home');
	}

	public function verify()
	{
		$this->load->library('image');
		$config = array(
			'name' => 'verify',
			'font' => FCPATH.APPPATH.'fonts/texb.ttf'
		);
		$this->image->verify($config);
	}

	//登录
	public function login()
	{
		if ($this->is_get())
		{
			$this->_login_get();
		}
		else
		{
			$this->_login_post();
		}
	}
	
	//登录页面
	protected function _login_get()
	{
		$this->template->display('home/login');
	}
	
	//登录提交
	protected function _login_post()
	{
		$username = post('username');
		$password = post('password');
		$verify = post('verify');
		
		$this->load->model('admin_model');
		if ( ! $this->admin_model->login($username, $password, $verify))
		{
			echo $this->admin_model->get_error();
			exit();
		}
	}
	
	//注销
	public function logout()
	{
		$this->load->model('admin_model');
		$this->admin_model->logout();
		
		msg('成功退出系统！', admin_url('home/login'));
	}
	
}